package com.laboratory.report.lab05.lab0503;

import lombok.AllArgsConstructor;
import lombok.SneakyThrows;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 测试
 */
public class Lab0503Main {

    @SneakyThrows
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(3);

        Torchbearer t1 = new Torchbearer("罗致焕", 0);
        Torchbearer t2 = new Torchbearer("景海鹏", 3);
        Torchbearer t3 = new Torchbearer("叶培建", 6);

        es.submit(t1);
        es.submit(t2);
        es.submit(t3).get();
    }

    @AllArgsConstructor
    public static class Torchbearer extends Thread {

        private String person;
        private int distance;

        @SneakyThrows
        @Override
        public void run() {
            while(distance>0) {
                System.out.println(person + "等待接力中...");
                --distance;
                Thread.sleep(1000);
            }
            System.out.println(person + "已接棒！");
        }
    }
}
